﻿using AutoMapper;
using CoreProject.DTO;
using CoreProject.IService;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace CoreProject.Api.Controllers
{
    [Route("api/[controller]")]
    [ApiController]

    public class SpecController : ControllerBase
    {
        private readonly IGoodsSpecService _service;
        private readonly IMapper _mapper;

        public SpecController(IGoodsSpecService service, IMapper mapper)
        {
            _service = service;
            _mapper = mapper;
        }
        // GET: api/<SpecController>
        [HttpGet]
       
        public async Task<ResultData<List<SpecDto>>> Get()
        {

            var list = from n in await _service.GetSpecKeys()
                       select new SpecDto()
                       {
                           GSKID = n.GskId,
                           Name = n.Name,
                           Values = from g in n.GoodsSpecValues
                                    select new SpecValueDto()
                                    {
                                        Code = g.Code,
                                        GSVID = g.GsvId,
                                        Value = g.Value
                                    }
                       };


            ResultData<List<SpecDto>> result = new ResultData<List<SpecDto>>();
            result.state = 200;
            result.code = "1";
            result.msg = "ok";
            result.data = list.ToList();
            return result;
        }
      
        
    }
}
